﻿// TcpipDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "TcpipDlg.h"
#include "afxdialogex.h"


// CTcpipDlg 对话框

IMPLEMENT_DYNAMIC(CTcpipDlg, CDialogEx)

CTcpipDlg::CTcpipDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_TCPIP, pParent)
	, MesFlag(FALSE)
	, MesPort(0)
	, Gongxu(_T(""))
	, Shebei(_T(""))
{

}

CTcpipDlg::~CTcpipDlg()
{
}

void CTcpipDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK1, MesFlag);
	DDX_Control(pDX, IDC_IPADDRESS1, MesIP);
	DDX_Text(pDX, IDC_EDIT1, MesPort);
	DDX_Text(pDX, IDC_EDIT2, Gongxu);
	DDX_Text(pDX, IDC_EDIT4, Shebei);
}


BEGIN_MESSAGE_MAP(CTcpipDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CTcpipDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CTcpipDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CTcpipDlg::OnBnClickedButton3)
END_MESSAGE_MAP()


// CTcpipDlg 消息处理程序


BOOL CTcpipDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	MesIP.SetWindowText(gSystemMgr.m_cstrIPMes);
	MesPort = gSystemMgr.m_nPortMes;
	MesFlag = gSystemMgr.MesFlag;

	Gongxu = gSystemMgr.Gongxu;
	Shebei = gSystemMgr.Shebei;

	UpdateData(FALSE);

	return TRUE;
}


void CTcpipDlg::OnBnClickedButton1()
{
	UpdateData(TRUE);

	MesIP.GetWindowText(gSystemMgr.m_cstrIPMes);
	gSystemMgr.m_nPortMes = MesPort;
	gSystemMgr.MesFlag = MesFlag;

	gSystemMgr.Gongxu = Gongxu;
	gSystemMgr.Shebei = Shebei;

	CString cstr;

	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"m_cstrIPMes", gSystemMgr.m_cstrIPMes);
	cstr.Format(L"%d", gSystemMgr.m_nPortMes);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"m_nPortMes", cstr);
	cstr.Format(L"%d", gSystemMgr.MesFlag);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"MesFlag", cstr);

	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"Gongxu", gSystemMgr.Gongxu);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"Shebei", gSystemMgr.Shebei);

	gSystemLog.DisplayLogAndSave(L"MES通讯保存数据完成", LV_EVENT);

}


void CTcpipDlg::OnBnClickedButton2()
{

	//gSystemMgr.m_nButtonValue = 50;
}


void CTcpipDlg::OnBnClickedButton3()
{
	gSystemMgr.MesOut("123", true);
	//gSystemMgr.m_nButtonValue = 51;
}
